var request = require("request");
var MyPromise = require('../lib/my-promise');

// var promise1 = new MyPromise((resolve) => {
//   request('https://www.baidu.com', function (error, response) {
//     if (!error && response.statusCode == 200) {
//       resolve('request1 success');
//     }
//   });
// });

// promise1.then(function(value) {
//   console.log(value);
// });

// var promise2 = new MyPromise((resolve, reject) => {
//   request('https://www.baidu.com', function (error, response) {
//     if (!error && response.statusCode == 200) {
//       reject('request2 failed');
//     }
//   });
// });

// promise2.then(function(value) {
//   console.log(value);
// }, function(reason) {
//   console.log(reason);
// });

var promise3 = new MyPromise((resolve, reject) => {
  request('https://www.baidu.com', function (error, response) {
    if (!error && response.statusCode == 200) {
      reject(new Error('request2 failed'));
    }
  });
});

const promise31 = promise3.then(null, err => Promise.reject(err))

promise31.then(null, (error) => {
  console.log('99999999999', error.message)
})